package com.xsr.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import javax.xml.crypto.Data;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.net.URLEncoder;

/**
 * @author 邢式瑞
 * @version 1.0
 * @project gp14Sm
 * @date 2022/9/9 19:27
 */

@Controller
@RequestMapping("/ford")
public class ForWardController {
 @GetMapping("/test01")
    public String  test01(Integer id){

     System.out.println(id);

     return "/hello";
    }
    @GetMapping("/test02")
    public String redirect01(Integer id, String name, RedirectAttributes redirectAttributes){
        System.out.println(id);
        System.out.println(name);
        redirectAttributes.addAttribute("id",id);
        
        try {
            name = URLEncoder.encode(name,"utf-8");
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        redirectAttributes.addAttribute("name",name);
        return "redirect:/ford/test03";
    }
    @GetMapping("/test03")
    public String redirect02(Integer id,String name ){
        System.out.println(id);
        try {
            name = URLDecoder.decode(name,"utf-8");
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        return "redirect:/index.jsp";
    }
}
